package com.swind.fast.modules.app.halali.partner.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.swind.fast.common.api.vo.Result;
import com.swind.fast.common.system.query.QueryGenerator;
import com.swind.fast.common.util.oConvertUtils;
import com.swind.fast.common.constant.CommonConstant;
import com.swind.fast.modules.app.halali.partner.entity.RestaurantMeal;
import com.swind.fast.modules.app.halali.partner.entity.RestaurantMealDeal;
import com.swind.fast.modules.app.halali.partner.entity.RestaurantMealDealItem;
import com.swind.fast.modules.app.halali.partner.service.IRestaurantMealService;
import com.swind.fast.modules.app.halali.partner.service.IRestaurantMealDealService;
import com.swind.fast.modules.app.halali.partner.service.IRestaurantMealDealItemService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import com.swind.fast.common.system.base.controller.SwindController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
// import com.swind.fast.common.aspect.annotation.AutoLog;

import com.swind.fast.modules.system.entity.SysAnnouncement;
import com.swind.fast.modules.system.entity.SysAnnouncementSend;
import com.swind.fast.modules.system.service.ISysAnnouncementSendService;
import com.swind.fast.modules.system.service.ISysAnnouncementService;
import java.util.Optional;
import com.swind.fast.modules.app.halali.partner.vo.request.DealVo;
import com.swind.fast.modules.app.halali.partner.vo.request.RankInfoVo;
import com.swind.fast.modules.app.halali.partner.component.HalaliUtils;
import org.springframework.http.MediaType;
import com.swind.fast.modules.app.halali.partner.vo.common.FileUploadVo;

 /**
 * @Description: 餐厅
 * @Author: swind
 * @Date:   2022-01-20
 * @Version: V1.0
 */
@Api(tags="06.商户端-套餐")
@RestController
@RequestMapping("/app/partner/deal")
@Slf4j
public class RestaurantDealController extends SwindController<RestaurantMealDeal, IRestaurantMealDealService> {
	@Autowired
	private HalaliUtils halaliUtils;

	@ApiOperation(value="套餐-列表", notes="")
	@GetMapping(value = "/list")
	public Result<List<RestaurantMealDeal>> queryDealListAction() {
		List<RestaurantMealDeal> list = this.service.getDealList();
		return Result.OK(list);
	}

	@ApiOperation(value="套餐-新增", notes="")
	@PostMapping(value = "/add")
	public Result<DealVo> addAction(@RequestBody() DealVo dealVo) {
		DealVo result = this.service.saveMain(dealVo);
		return Result.OK(result);
	}

	@ApiOperation(value="套餐-更新", notes="")
	@PostMapping(value = "/update")
	public Result<DealVo> updateAction(@RequestBody() DealVo dealVo) {
		DealVo result = this.service.updateInfo(dealVo);
		return Result.OK(result);
	}

	@ApiOperation(value="套餐-排序", notes="")
	@PostMapping(value = "/rank/update")
	public Result<?> rankUpdateAction(@RequestBody List<RankInfoVo> items) {
		this.service.updateRank(items);
		return Result.OK();
	}

	@ApiOperation(value="套餐-详情", notes="")
	@GetMapping(value = "/detail")
	public Result<RestaurantMealDeal> detailAction(@RequestParam(name="id", required=true) String id) {
		RestaurantMealDeal item = this.service.getDetailById(id);
		if (item == null) {
			return Result.errorT(null);
		}
		return Result.OK(item);
	}

	@ApiOperation(value="套餐-图片", produces=MediaType.MULTIPART_FORM_DATA_VALUE)
    @PostMapping(value = "/update/pic", headers="content-type=multipart/form-data")
    public Result<FileUploadVo> updatePic(HttpServletRequest request,HttpServletResponse response) {
    	MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        MultipartFile file = multipartRequest.getFile("file");// 获取上传文件对象
        String bizPath = "halali/deal";
        FileUploadVo fileVo = halaliUtils.uploadLocal(file, bizPath);
        return Result.OK(fileVo);
    }

	@ApiOperation(value="套餐-删除", notes="")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		this.service.removeById(id);
		return Result.OK();
	}
}
